package com.example.demo01.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author wangxun
 * @EnableSwagger2 启动swagger
 * swagger 地址:
 * http://localhost:8080/swagger-ui/
 */
@Configuration
@EnableSwagger2
public class Swagger2Config {

    /**
     * 负责接口文档的呈现  以及  接口的配置
     */
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                // 哪个包下的http接口配置到swagger文档中
                .apis(RequestHandlerSelectors.basePackage("com.example.demo01.controller"))
                //任何一个接口都配置到swagger文档中
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                // 当前文档标题
                .title("自学开发文档")
                .description("SpringBoot整合Swagger，详细信息......")
                .contact(new Contact("王迅", "www.baidu.comm", "1844131523@qq.com"))
                .version("1.0")
                .build();
    }
}
